home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Information / WebSites / Imagine / arexx / screwt.lzx / ScrewThread.irx
Text File  |  1998-10-01  |  9KB  |  414 lines

  1. /*
  2.             Imagine5.0 Arexx Screwthread Creator v3
  3.  
  4.               "What use it is, I'll never know !!"
  5.  
  6.                              :-)
  7.  
  8.              1996 Rob Darke - Freely distributable
  9.     robda@parallel.demon.co.uk  or  iml@parallel.demon.co.uk
  10.  
  11.                   Omigod - it's got bigger ...
  12.  
  13.         Please give me some feedback on this script :-)
  14. */
  15.  
  16. ADDRESS 'Imagine.1'
  17.  
  18. DISPLAYREXXPTR ON
  19.  
  20. NL = '0A'x
  21.  
  22. IF ~EXISTS('LIBS:rexxreqtools.library') THEN DO
  23.    NOTIFY 'Please install the rexxreqtools.library in your LIBS: directory'
  24.    NOTIFY 'It is available from /pub/aminet/util/rexx/RexxReqTools.lha'
  25.    CALL desist
  26. END
  27. CALL ADDLIB('rexxreqtools.library',0,-30,0)
  28.  
  29. IF ~EXISTS('LIBS:rexxmathlib.library') THEN DO
  30.    CALL rtezrequest('Please install the rexxmathlib.library into your LIBS: directory' || NL || NL ||,
  31.                     'The library is available from pub/aminet/util/rexx/RexxMathLib1.3.lha','Great, thanks!','Go get RexxMathLib.library','rt_reqpos = reqpos_centerscr')
  32.    CALL desist
  33. END
  34. CALL ADDLIB('rexxmathlib.library',0,-30,0)
  35.  
  36. CALL rtezrequest('ScrewThread Creator -  1996 Rob Darke','Wow!','Screw Threadz','rt_reqpos = reqpos_centerscr')
  37.  
  38. radius.3 = rtgetlong(20,'Enter outer thread radius','Screw Threadsize',,'rt_reqpos = reqpos_centerscr')
  39.  
  40. if ~rtresult then CALL desist
  41.  
  42. radius.2 = rtgetlong(15,'Enter inner thread radius','Screw Threadsize',,'rt_reqpos = reqpos_centerscr')
  43.  
  44. if ~rtresult then CALL desist
  45.  
  46. distance = rtgetlong(100,'Enter length of threadded portion of screw','Thread Length',,'rt_reqpos = reqpos_centerscr')
  47.  
  48. if ~rtresult then CALL desist
  49.  
  50. blanklength = rtgetlong(0,'Enter length of blank portion of screw','Blank Length',,'rt_reqpos = reqpos_centerscr')
  51.  
  52. if ~rtresult then CALL desist
  53.  
  54. p_pgap = rtgetlong(5,'Enter outer thread peak-to-peak gap','Thread spacing',,'rt_reqpos = reqpos_centerscr')
  55.  
  56. if ~rtresult then CALL desist
  57.  
  58. no_rot = (distance / p_pgap)
  59. pp_rot = 0
  60. points = 0
  61. do while (pp_rot = 0)
  62.    pp_rot = rtgetlong(8,'Enter number of points per revolution','Detail Coarseness',,'rt_reqpos = reqpos_centerscr')
  63.    if ~rtresult then CALL desist
  64.    points = (pp_rot * no_rot)
  65.    if points > 16383 then do
  66.       ret = rtezrequest(pp_rot' points per rotation would make too many points' || NL ||,
  67.                               '   in the final object. Try something smaller.','_OK|_Abort','Smaller, please','rt_reqpos = reqpos_centerscr')
  68.       if ~ret then CALL desist
  69.       pp_rot = 0
  70.    end
  71. end
  72.  
  73. ret = rtezrequest('Please select logarithmic or linear scaling','_Logarithmic|_Abort|_Linear','Choose scaling','rt_reqpos = reqpos_centerscr')
  74.  
  75. if ret = 2 then CALL desist
  76.  
  77. if ret = 1 then type = 'logarithmic'
  78. else type = 'linear'
  79.  
  80. ret = rtezrequest('Would you like a simple countersunk head' || NL ||,
  81.                   '       on the top of your screw ?','_Yes|_No|_Abort','Select Screwhead','rt_reqpos = reqpos_centerscr')
  82.  
  83. if ret = 2 then head = 'None'
  84. if ret = 1 then head = 'Countersunk'
  85. if ret = 0 then CALL desist
  86.  
  87. headdepth = '--'
  88. headradius = '--'
  89.  
  90. if (head ~= 'None') then do
  91.  
  92.    headdepth = rtgetlong(15,'Enter head depth','Screwhead depth',,'rt_reqpos = reqpos_centerscr')
  93.  
  94.    if ~rtresult then CALL desist
  95.  
  96.    headradius = rtgetlong(30,'Enter head radius','Screwhead radius',,'rt_reqpos = reqpos_centerscr')
  97.  
  98.    if ~rtresult then CALL desist
  99.  
  100. end
  101.  
  102. axisname = ''
  103. do while (axisname = '')
  104.    axisname = rtgetstring('SCREWTHREAD','Enter name for screw object','Object name',,'rt_reqpos = reqpos_centerscr')
  105. end
  106.  
  107. if ~rtresult then CALL desist
  108.  
  109. ret = rtezrequest('I am going to make a 'type' screw' || NL ||,
  110.                   'with the following parameters ...' || NL || NL ||,
  111.                   '           Outer thread = 'radius.3' iu' || NL ||,
  112.                   '           Inner thread = 'radius.2' iu' || NL ||,
  113.                   ' Outer thread peak-peak = 'p_pgap' iu' || NL ||,
  114.                   '           Screw length = 'distance' iu' || NL ||,
  115.                   '  Points per revolution = 'pp_rot' points' || NL ||,
  116.                   '                   Head = 'head || NL ||,
  117.                   '             Head depth = 'headdepth || NL ||,
  118.                   '            Head radius = 'headradius || NL ||,
  119.                   '            Object name = 'axisname,' _Ok |_Abort','Check details','rt_reqpos = reqpos_centerscr')
  120.  
  121. if ~ret then CALL desist
  122.  
  123. ret = rtezrequest('It is imperative that you don`t click anywhere whilst I`m' || NL ||,
  124.                   ' doing this, or else things will go very pear-shaped !!!','_Fair Enough|_Abort','Warning','rt_reqpos = reqpos_centerscr')
  125.  
  126. if ~ret then CALL desist
  127.  
  128. /* Let's do it ... */
  129.  
  130. singleangle = (360 / pp_rot)
  131. singlestep = (p_pgap / pp_rot)
  132. stepin = (radius.3 / points)
  133. offset = (p_pgap / 2)
  134. pi = 3.141592654
  135. po = (pi * 2)
  136. eachstep = (0.9 / points)
  137. raddiff = (radius.3 - radius.2)
  138. diffgrad = (raddiff / (pp_rot - 1))
  139.  
  140. DETAILEDITOR
  141. ZOOM 1
  142. CENTERAT 0 0 0
  143. MULTIPICKOFF
  144. OBJECTMODE
  145.  
  146. do i = 1 to 5
  147.  
  148.    ADDAXIS
  149.    PICK
  150.    ATTRIB.OBJECTNAME = axisname'.'i
  151.    SETATTRIBUTES OBJECTNAME
  152.  
  153. end
  154.  
  155. OBJECTMODE
  156. PICK axisname'.3'
  157. ADDPOINTMODE
  158. k = 1
  159. startradius = radius.3
  160.  
  161. do j = 0 to (points-1)
  162.  
  163.    se = ((((singleangle*j) / 360)*po)-pi)
  164.    x = (radius.3 * sin(se))
  165.    y = (radius.3 * cos(se))
  166.    z = (-(j * singlestep))
  167.  
  168.    ADDPOINT x y z
  169.  
  170.    if j > (pp_rot - 1) then do
  171.  
  172.       if type = 'linear' then do
  173.          radius.3 = radius.3 - stepin
  174.       end
  175.       else do
  176.          logscale = (log10(k*10))
  177.          radius.3 = (startradius * logscale)
  178.          k = (k - eachstep)
  179.       end
  180.    end
  181.  
  182. end
  183.  
  184. OBJECTMODE
  185. PICK axisname'.1'
  186. ADDPOINTMODE
  187. k = 1
  188. radius.3 = startradius
  189.  
  190. do j = 0 to ((points-1)+(pp_rot))
  191.  
  192.    se = ((((singleangle*j) / 360)*po)-pi)
  193.    x = (radius.3 * sin(se))
  194.    y = (radius.3 * cos(se))
  195.    z = (-(j * singlestep))
  196.  
  197.    if j > (pp_rot-1) then do
  198.  
  199.       ADDPOINT x y z
  200.  
  201.       if type = 'linear' then do
  202.          radius.3 = radius.3 - stepin
  203.       end
  204.       else do
  205.          logscale = (log10(k*10))
  206.          radius.3 = (startradius * logscale)
  207.          k = (k - eachstep)
  208.          if k < 0.1 then k = 0.1
  209.  
  210.       end
  211.  
  212.    end
  213.  
  214. end
  215.  
  216. OBJECTMODE
  217. PICK axisname'.2'
  218. ADDPOINTMODE
  219. k = 1
  220. radius.3 = startradius
  221. radius.2 = radius.3
  222.  
  223. do j = 0 to (points-1)
  224.  
  225.    se = ((((singleangle*j) / 360)*po)-pi)
  226.  
  227.    if radius.2 > 0 then do
  228.       x = (radius.2 * sin(se))
  229.       y = (radius.2 * cos(se))
  230.    end
  231.    else do
  232.       x = 0
  233.       y = 0
  234.    end
  235.  
  236.    z = (-((j * singlestep) + offset))
  237.  
  238.    ADDPOINT x y z
  239.  
  240.    if j < pp_rot then do
  241.       radius.3 = (radius.3 - diffgrad)
  242.       radius.2 = radius.3
  243.    end
  244.    else do
  245.       if type = 'linear' then do
  246.          radius.3 = (radius.3 - stepin)
  247.          radius.2 = (radius.3 - raddiff)
  248.       end
  249.       else do
  250.          logscale = (log10(k*10))
  251.          radius.3 = (startradius * logscale)
  252.          radius.2 = (radius.3 - raddiff)
  253.          k = (k - eachstep)
  254.       end
  255.    end
  256.  
  257. end
  258.  
  259. OBJECTMODE
  260. PICK axisname'.4'
  261. ADDPOINTMODE
  262. radius.3 = startradius
  263. z = blanklength
  264.  
  265. do j = 0 to pp_rot
  266.  
  267.    se = ((((singleangle*j) / 360)*po)-pi)
  268.  
  269.    x = (radius.3 * sin(se))
  270.    y = (radius.3 * cos(se))
  271.  
  272.    ADDPOINT x y z
  273.  
  274. end
  275.  
  276. OBJECTMODE
  277. PICK axisname'.5'
  278. ADDPOINTMODE
  279. radius.3 = startradius
  280.  
  281. do j = 0 to pp_rot
  282.  
  283.    se = ((((singleangle*j) / 360)*po)-pi)
  284.  
  285.    x = (radius.3 * sin(se))
  286.    y = (radius.3 * cos(se))
  287.    z = (-(j * singlestep))
  288.  
  289.    ADDPOINT x y z
  290.  
  291. end
  292.  
  293. do i = 1 to 3
  294.  
  295.    OBJECTMODE
  296.    PICK axisname'.'i
  297.  
  298.    ADDEDGEMODE
  299.  
  300.    do j = 2 to points
  301.  
  302.       ADDEDGE (j-1) j
  303.  
  304.    end
  305.  
  306. end
  307.  
  308. do i = 4 to 5
  309.  
  310.    OBJECTMODE
  311.    PICK axisname'.'i
  312.  
  313.    ADDEDGEMODE
  314.  
  315.    do j = 1 to pp_rot
  316.  
  317.       ADDEDGE j (j+1)
  318.  
  319.    end
  320.  
  321. end
  322.  
  323. OBJECTMODE
  324. UNPICK ALL
  325.  
  326. PICK axisname'.2'
  327. SAVEOBJECT 't:tempobj1.iob'
  328. LOADOBJECT 't:tempobj1.iob'
  329. ADDRESS COMMAND 'delete t:tempobj1.iob >nil:'
  330.  
  331. if (head = 'Countersunk') then do
  332.    PICK axisname'.4'
  333.    SAVEOBJECT 't:tempobj2.iob'
  334.    LOADOBJECT 't:tempobj2.iob'
  335.    ADDRESS COMMAND 'delete t:tempobj2.iob >nil:'
  336.    UNPICK ALL
  337.    ADDAXIS
  338.    PICK
  339.    ATTRIB.OBJECTNAME = axisname'.9'
  340.    SETATTRIBUTES OBJECTNAME
  341.    ADDAXIS
  342.    PICK
  343.    ATTRIB.OBJECTNAME = axisname'.8'
  344.    SETATTRIBUTES OBJECTNAME
  345.    ADDPOINTMODE
  346.    z = (blanklength + headdepth)
  347.    do j = 0 to pp_rot
  348.       se = ((((singleangle*j) / 360)*po)-pi)
  349.       x = (headradius * sin(se))
  350.       y = (headradius * cos(se))
  351.       ADDPOINT x y z
  352.    end
  353.    ADDEDGEMODE
  354.    do j = 1 to pp_rot
  355.       ADDEDGE j (j+1)
  356.    end
  357.    OBJECTMODE
  358.    PICK axisname'.9'
  359.    ADDPOINTMODE
  360.    do j = 0 to pp_rot
  361.       ADDPOINT 0 0 z
  362.    end
  363.    ADDEDGEMODE
  364.    do j = 1 to pp_rot
  365.       ADDEDGE j (j+1)
  366.    end
  367.    OBJECTMODE
  368.    UNPICK ALL
  369.    MULTIPICKON
  370.    PICK axisname'.9'
  371.    PICK axisname'.8'
  372.    PICK axisname'.7'
  373.    MULTIPICKOFF
  374.    SKIN
  375. end
  376.  
  377. UNPICK ALL
  378. MULTIPICKON
  379. PICK axisname'.3'
  380. PICK axisname'.2'
  381. MULTIPICKOFF
  382. SKIN
  383. UNPICK ALL
  384. MULTIPICKON
  385. PICK axisname'.6'
  386. PICK axisname'.1'
  387. MULTIPICKOFF
  388. SKIN
  389. UNPICK ALL
  390. MULTIPICKON
  391. PICK axisname'.4'
  392. PICK axisname'.5'
  393. MULTIPICKOFF
  394. SKIN
  395. UNPICK ALL
  396. MULTIPICKON
  397. PICK axisname'.4'
  398. PICK axisname'.3'
  399. PICK axisname'.6'
  400. if (head = 'Countersunk') then PICK axisname'.9'
  401. MULTIPICKOFF
  402. MERGE
  403. ATTRIB.OBJECTNAME = axisname
  404. SETATTRIBUTES OBJECTNAME
  405. DISPLAYREDRAW
  406. DISPLAYREXXPTR OFF
  407. CALL rtezrequest('Job done. Your screwthread awaits ...','Thanks Rob!','Screw Threadz','rt_reqpos = reqpos_centerscr')
  408. exit
  409.  
  410. desist: procedure
  411.    DISPLAYREXXPTR OFF
  412.    exit
  413. end
  414.